package net.mihome.app.bean;

import net.mihome.app.bean.net.ResponsePojo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Shop extends Entity{
	private int id;
	private String name;
	private String desc;
	private String contract;
	private String img;
	private Double lon;
    private int support;
    private int callSum;
    private int tramp;
    private ShopType shopType;
	private Double lat;
	private String create_at;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public String getContract() {
		return contract;
	}
	public void setContract(String contract) {
		this.contract = contract;
	}
	public String getImg() {
		return img;
	}
	public void setImg(String img) {
		this.img = img;
	}
	public Double getLon() {
		return lon;
	}
	public void setLon(Double lon) {
		this.lon = lon;
	}
	public Double getLat() {
		return lat;
	}
	public void setLat(Double lat) {
		this.lat = lat;
	}
	public String getCreate_at() {
		return create_at;
	}
	public void setCreate_at(String create_at) {
		this.create_at = create_at;
	}

    public int getSupport() {
        return support;
    }

    public void setSupport(int support) {
        this.support = support;
    }

    public int getTramp() {
        return tramp;
    }

    public void setTramp(int tramp) {
        this.tramp = tramp;
    }

    public int getCallSum() {
        return callSum;
    }

    public void setCallSum(int callSum) {
        this.callSum = callSum;
    }

    public static Shop parse(Map map){
		Shop shop=new Shop();
		Double idsDouble=(Double) map.get("id");
		Double supportDouble=(Double) map.get("support_sum");
		Double trampDouble=(Double) map.get("tramp_sum");
		Double callSumDouble=(Double) map.get("call_sum");
        if(supportDouble==null){
            supportDouble=new Double(0);
        }
        if(trampDouble==null){
            trampDouble=new Double(0);
        }
        shop.setCallSum(callSumDouble.intValue());
        shop.setSupport(supportDouble.intValue());
        shop.setTramp(trampDouble.intValue());
		shop.setId(idsDouble.intValue());
		shop.setName((String) map.get("name"));
		shop.setDesc((String) map.get("desc"));
		shop.setContract((String) map.get("contract"));
		shop.setImg((String) map.get("img"));
		shop.setLon((Double) map.get("lon"));
		shop.setLat((Double) map.get("lat"));
		shop.setCreate_at((String) map.get("create_at"));
        shop.setShopType(ShopType.parse((Map) map.get("shop_type")));
		return shop;
	}
    public static List<Shop> parserList(ResponsePojo<List<Map>> responsePojo){
        if(responsePojo==null||responsePojo.getData()==null){
            throw new NullPointerException("无返回数据");
        }else{
            List<Shop> shopList=new ArrayList<>();
            List<Map> mapList=responsePojo.getData();
            Iterator<Map> iterator=mapList.iterator();
            while(iterator.hasNext()){
                Map map=iterator.next();
                Shop shop=parse(map);
                shopList.add(shop);
            }
            return shopList;
        }
    }

    public ShopType getShopType() {
        return shopType;
    }

    public void setShopType(ShopType shopType) {
        this.shopType = shopType;
    }
}
